"""
内容:将添加缺货封装成一个类
作者:Zhou
"""

"""前置条件,已经登录成功"""
#引入
from ECShop_no9.common.base import create_browser,Base,create_browser_op
import time

#将库存为1的商品,修改购买数量为2
class PageNoCommodity01(Base):
    #属性
    url='http://localhost:8080/ecshop/user.php'
    purchase=("xpath",("//div[@class='textInfo']/form/ul/li[7]/table/tbody/tr/td/a/img"))
    num=('name','number')
    first=('link text','首页')
    zipai=('xpath',("//img[@src='images/201605/thumb_img/63_thumb_G_1462953395609.jpg']"))
    buy=('xpath',("//img[@src='themes/default/images/buybtn1.png']"))
    # older_number=('xpath',("//div[@class='flowBox']/h6/font"))
    older_number_user=("xpath",("//div[@class='AreaR']/div/div/div/table/tbody/tr[2]/td/a"))
    user=('link text','用户中心')
    user_no_commodity=('xpath',("//img[@src='themes/default/images/u8.gif']"))

    #方法
    #打开网页
    def page_no_commodity_web(self):
        self.base_open_web(self.url)
    #点击首页
    def page_no_commodity_first(self):
        self.base_click(self.first)
    #点击自拍杆
    def page_no_commodity_zipai(self):
        self.base_click(self.zipai)
    #点击购买
    def page_no_commodity_buy(self):
        self.base_click(self.buy)
    #点击弹窗确定按钮
    def page_no_commodity_click_pop(self):
        self.base_alert()
    #进入用户中心
    def page_no_commodity_user(self):
        self.base_click(self.user)
    #进入缺货登记
    def page_no_commodity_user_no_commodity(self):
        self.base_click(self.user_no_commodity)
    #获取最新的缺货登记
    def page_no_commodity_older_number_user(self):
        result_user=self.base_get_text(self.older_number_user)
        return result_user
    #关闭网页
    def page_no_commodity_quit(self):
        self.base_quit()

if __name__ == '__main__':
    n1=PageNoCommodity01(create_browser_op(r'C:\Users\lenovo\AppData\Local\Google\Chrome\User Data'))
    n1.page_no_commodity_web()
    n1.page_no_commodity_first()
    n1.page_no_commodity_zipai()
    time.sleep(2)
    n1.page_no_commodity_buy()
    time.sleep(5)
    n1.page_no_commodity_click_pop()
    time.sleep(2)
    n1.page_no_commodity_user()
    n1.page_no_commodity_user_no_commodity()
    time.sleep(3)
    print(n1.page_no_commodity_older_number_user())
    # n1.page_no_commodity_quit()
